package br.com.playonline.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import br.com.playonline.bussines.CarrinhoBU;
import br.com.playonline.dto.CarrinhoAdicionarBolaoDTO;
import br.com.playonline.dto.CarrinhoConverterList;
import br.com.playonline.dto.CarrinhoDTO;

@RestController
@RequestMapping(value = "/carrinho")
public class CarrinhoRest {
	
	@Autowired
	CarrinhoBU carrinhoBU;
	
	@RequestMapping(value = "/adicionarCarrinhoBolao",method = RequestMethod.POST)
	public @ResponseBody void adicionarBolao(@RequestBody CarrinhoAdicionarBolaoDTO carrinhoAdicionarBolaoDTO){
		this.carrinhoBU.adicionarBolao(carrinhoAdicionarBolaoDTO.getIdUsuario(), carrinhoAdicionarBolaoDTO.getIdBolao(), carrinhoAdicionarBolaoDTO.getQtdCota());
	}
	
	@RequestMapping(value = "/findCarrinhoByUsuario/{idUsuario}",method = RequestMethod.GET)
	public @ResponseBody List<CarrinhoDTO> findCarrinhoByUsuario(@PathVariable("idUsuario") Long idUsuario){
		return this.carrinhoBU.findCarrinhoByUsuario(idUsuario);
	}
	
	@RequestMapping(value = "/removerTodos",method = RequestMethod.POST)
	public @ResponseBody void removerTodos(@RequestBody CarrinhoAdicionarBolaoDTO carrinhoAdicionarBolaoDTO){
		this.carrinhoBU.removerTodos(carrinhoAdicionarBolaoDTO.getIdUsuario());
	}
	
	@RequestMapping(value = "/removerByBolao",method = RequestMethod.POST)
	public @ResponseBody void removerByBolao(@RequestBody CarrinhoAdicionarBolaoDTO adicionarBolaoDTO){
		this.carrinhoBU.removerByBolao(adicionarBolaoDTO);
	}
	
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	public @ResponseBody void add(@RequestBody CarrinhoConverterList carrinhos){
//		this.carrinhoBU.removerByBolao(adicionarBolaoDTO);
		System.out.println("POST FUNFANDO");
		System.out.println(carrinhos.getCarrinhoDTOs().size());
//		return "SUCCESS";
	}

}
